﻿using Coldairarrow.Business.MEGA;
using Coldairarrow.Entity.MEGA;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.MEGA
{
    [Route("/MEGA/[controller]/[action]")]
    public class MEGA_XZQHController : BaseApiController
    {
        #region DI

        public MEGA_XZQHController(IMEGA_XZQHBusiness mEGA_XZQHBus)
        {
            _mEGA_XZQHBus = mEGA_XZQHBus;
        }

        IMEGA_XZQHBusiness _mEGA_XZQHBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<MEGA_XZQH>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _mEGA_XZQHBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<MEGA_XZQH> GetTheData(IdInputDTO input)
        {
            return await _mEGA_XZQHBus.GetTheDataAsync(input.id);
        }

        /// <summary>
        /// 查询行政区划列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<Base_DepartmentTreeDTO>> GetAllTreeDataList(DepartmentsTreeInputDTO input)
        {
            return await _mEGA_XZQHBus.GetAllTreeDataListAsync(input);
        }

        /// <summary>
        /// 查询省级列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<Base_DepartmentTreeDTO>> GetOneTreeDataList(DepartmentsTreeInputDTO input)
        {
            return await _mEGA_XZQHBus.GetOneTreeDataListAsync(input);
        }

        /// <summary>
        /// 查询市级列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<Base_DepartmentTreeDTO>> GetTwoTreeDataList(DepartmentsTreeInputDTO input)
        {
            return await _mEGA_XZQHBus.GetTwoTreeDataListAsync(input);
        }

        /// <summary>
        /// 查询区/县级列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<Base_DepartmentTreeDTO>> GetThreeTreeDataList(DepartmentsTreeInputDTO input)
        {
            return await _mEGA_XZQHBus.GetThreeTreeDataListAsync(input);
        }

        /// <summary>
        ///行政区划数据导出
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public  Task<object> ExportEXCEL()
        {
            return  _mEGA_XZQHBus.ExportToExcelData();
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(MEGA_XZQH data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _mEGA_XZQHBus.AddDataAsync(data);
            }
            else
            {
                await _mEGA_XZQHBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _mEGA_XZQHBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}